<?php

namespace App\Models\Product;

use App\Models\Config as ConfigModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Comment extends Model
{
    use HasFactory;

    // use SoftDeletes;

    protected $table = 'order_product';

    // 自动写入时间戳
    public $timestamps = true;

    // 时间类型
    protected $dateFormat = 'U';

    // 自定义创建时间字段
    // const CREATED_AT = 'updatetime';

    // 自定义更新时间字段
    const UPDATED_AT = 'updatetime';

    // 软删除字段
    // const DELETED_AT = 'deletetime';
    protected $appends = [
        'updatetime_text',
        'proimg_cdn'
    ];


    protected $guarded = [];

    public function business()
    {
        // return 1111;
        // return $this->belongsTo('app\Models\Product\Product', 'id', 'proid', [], 'LEFT')->setEagerlyType(0);
        return $this->belongsTo('App\Models\Business\Business', 'busid', 'id');
    }

    public function getUpdatetimeTextAttribute()
    {
        return date('Y-m-d H:i:s',strtotime($this->updatetime));
    }

    public function getProimgCdnAttribute()
    {
        $cdn = ConfigModel::where('name','url')->value('value');
        
        $url = $cdn . '/shop/product/product/proimg';
        // dd($url);
        $thumbs = httpRequest($url,['orderid' => $this->orderid]);
        
        // dd($thumbs);
        $thumbs = json_decode($thumbs,true);
        // dd($thumbs);
        return $thumbs;
    }

}
